package com.fzg.common.demo.hutool;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import cn.hutool.extra.emoji.EmojiUtil;
import cn.hutool.jwt.JWT;
import cn.hutool.jwt.JWTHeader;
import cn.hutool.jwt.JWTUtil;
import cn.hutool.system.HostInfo;
import cn.hutool.system.RuntimeInfo;
import cn.hutool.system.SystemUtil;
import cn.hutool.system.UserInfo;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

/**
 * create by fzg
 * 2022/12/13 16:37
 */

@Slf4j
public class Demo12 {
    public static void main(String[] args) {
        String s = EmojiUtil.toAlias("😀");
        log.info(s);

        String s1 = EmojiUtil.toUnicode(":grinning:");
        log.info(s1);

        String s2 = EmojiUtil.toAlias("(❤ ω ❤)");
        log.info(s2);
        String s3 = EmojiUtil.toUnicode("(:heart: ω :heart:)");
        log.info(s3);

        UserInfo userInfo = SystemUtil.getUserInfo();
        log.info(userInfo.toString());
        HostInfo hostInfo = SystemUtil.getHostInfo();
        log.info(hostInfo.toString());
        RuntimeInfo runtimeInfo = SystemUtil.getRuntimeInfo();
        log.info(runtimeInfo.toString());

        LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(200, 100);
        lineCaptcha.write("C:\\Users\\Asus\\Desktop\\temp\\imageCode.jpg");
        String code = lineCaptcha.getCode();
        log.info(code);
        boolean h8w4m = lineCaptcha.verify("h8w4m");
        log.info(h8w4m + "");

        Map<String, Object> map = new HashMap<String, Object>() {
            private static final long serialVersionUID = 1L;
            {
                put("uid", Integer.parseInt("123"));
                put("expire_time", System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 15);
            }
        };
        String token = JWTUtil.createToken(map, "1234".getBytes());
        log.info(token);

        String rightToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9." +
                "eyJzdWIiOiIxMjM0NTY3ODkwIiwiYWRtaW4iOnRydWUsIm5hbWUiOiJsb29seSJ9." +
                "U2aQkC2THYV9L0fTN-yBBI7gmo5xhmvMhATtu8v0zEA";

        // final JWT jwt = JWTUtil.parseToken(rightToken);
        JWT jwt = JWT.of(rightToken);

        Object header = jwt.getHeader(JWTHeader.TYPE);
        log.info(header.toString());
        Object sub = jwt.getPayload("sub");
        log.info(sub.toString());

        boolean verify = jwt.verify();
        log.info(verify + "");
        String algorithm = jwt.getAlgorithm();
        log.info(algorithm);
    }
}
